3D Graphics Engine File Formats - by Jum Hig '98
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Updated 18/7/1999


1. Model Format (.3DO files) (ver 3)
~~~~~~~~~~~~~~~
.3DO files are editable text files (ascii).
Each line must begin with a valid command.
The commands are:

!
vert
norm
poly
colour
shade
gouraud
filling
texture
texmap
end

Description of commands:

!
This marks the line as a comment line.

vert fX fY fZ
This specifies a vertex co-ordinate.

norm fX fY fZ
This specifies a normal vector. 

poly inumverts, iindex1, iindex2, ..., iindexn, sztexmap
This specifies a polygon consisting of inumvert vertices which
are iindex1, iindex2 etc.

colour n fR fG fB
This specifies the colour of vertex n of the current poly.
If n=0 specifies colour of entire poly if filling=0.

texture n
This specifies the texture map index. Default 0.

texvert n fU fV
This specifies the texture co-ordinate for vertex n of the current
polygon, in texture sztexture above.

shade 0/1
This specifies whether the poly is to be light-shaded or not.
Default 0.

gouraud 0/1
This specifies whether gouraud shading is to be used (uses normals).
Default 0.

filling 0/1/2
Type of poly rendering - 0 = solid colour, 1 = colour gradient,
2 = texture-mapped.

end
Marks the end of the file (required!).



2. Scene Format (.scn files)
~~~~~~~~~~~~~~~

The scene file has a similar format to the model file, but
has different commands:

Comments:
! line starts with a !

Lights:
light sztype, fX, fY, fZ, fR, fG, fB
(where type = "omni" or "distant")

Camera:
camera fX, fY, fZ, fdX, fdY, fdZ, fuX, fuY, fuZ, fviewangle

Object:
object "filename.3do", fX, fY, fZ, frX, frY, frZ, fsX, fsY, fsZ
 
"end" to end file

Take a look at a .scn file and .3do file for clarification.



3. Simple 3D Engine Layout

Set up screen, c-buffer, z-buffer. 
Load scene file (includes loading models)
Calculate vertex normals
Start loop
Reverse-calculate distant light dirns
Xform instances into camera space and filter (mark)
For every unfiltered instance:
	Xform unfiltered instance verts in model space (rot and scale)
	Rotate unfiltered instance normals in model space
	Xform unfiltered instance verts to world space (translate)
	Xform unfiltered instance verts to camera space
	For every polygon in this instance
		Cull polygons
		Light polygons (calc. lighted colour at verts)
		Clip polygons to frustum
		Render polys to c-buffer and z-buffer
	Next poly
Next instance
Blit c-buffer to screen
		

 